5 # This program imports iChat logs using the program Logorrhea. Get it from
6 # http://spiny.com/logorrhea/
8 # Using Logorrhea, export all of your chats.
10 # Then run this script with "ichat2adium.pl filename" or run from the same
11 # directory as the exported contents.
13 # If you pass the "--usernames" flag, the script will prompt you for the
14 # usernames of the various aliases.
16 # The "--primary-user USERNAME" flag will set the name of the user to your
19 # Records that make no sense will be sent to "adiumLogs/bad".
21 # You should be able to drop the adiumLogs folder into ~/Library/Application
22 # Support/Users/YOU/Logs/.
37 $file = "iChat Export.txt";
39 for (my $i = 1; $i < @ARGV; $i++) {
40 if ($ARGV[$i] eq "--usernames") {
43 if($ARGV[$i] eq "--primary-user" ) {
44 $primary = $ARGV[$i + 1];
47 open(FILE
, $file) or die qq{Unable to
open "$file": $!};
56 $base_out = "AIM.$primary";
58 $base_out = "AIM.iChatLogs";
62 mkdir($base_out, 0777) unless (-d
$base_out);
64 my $outfile = "$base_out/bad";
68 for (my $i = 0; $i < @input; $i++) {
69 my ($chatname, $sender, $date, $time, $message);
70 my ($day, $month, $year);
71 my ($hh, $mm, $ss, $modTime);
75 ($chatname, $sender, $date, $time, $message) =
76 /(.*?)\t(.*?)\t(.*?)\t(.*?)\t.*?\t(.*)\r/s;
81 ($month, $day, $year) = /(\d\d)\/(\d\d
)\
/(\d\d\d\d)/;
84 if($users && $chatname && $sender) {
86 for(my $j = 0; $j < @chatnames; $j++) {
87 if ($chatnames[$j] eq $chatname) {
89 $chatname = $usernames[$j];
93 push(@chatnames, $chatname);
94 print "Enter username associated with $chatname [$sender]:";
98 if(length($input) == 0) {
99 push(@usernames, $sender);
102 push(@usernames, $input);
110 if($chatname && $sender && $date && $month && $day && $year && $message) {
112 mkdir("$base_out/$chatname", 0777) unless (-d
"$base_out/$chatname");
114 $outfile = "$base_out/$chatname/$chatname ($year|$month|$day).adiumLog";
115 open(OUT
, ">>$outfile");
116 print OUT
"$time $sender: $message\n";
118 $outfile = "$base_out/bad";
119 open(OUT
, ">>$outfile");
120 print OUT
"$input[$i]";
121 print "Bad record found at line $i. Logged in $base_out/bad.\n";
125 ($hh, $mm, $ss) = $time =~ /(\d+):(\d+):(\d+)/;
126 $modTime = timelocal
($ss, $mm, $hh, $day, $month - 1, $year);
127 utime time, $modTime, $outfile;